//
//  TZJIngPinViewCell.m
//  XMLYFM
//
//  Created by dllo on 15/12/23.
//  Copyright © 2015年 zzl. All rights reserved.
//

#import "TZJIngPinViewCell.h"
#import "TZjingPInDetailViewCell.h"
#import "TZJingPinModel.h"
@interface TZJIngPinViewCell()<UICollectionViewDataSource,UICollectionViewDelegate>
@property(nonatomic,retain)UICollectionView *myCollectionView;
@property(nonatomic,retain)NSMutableArray *allmodelarray;

@end

@implementation TZJIngPinViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self creatSubView];
        self.allmodelarray = [NSMutableArray array];
        
    }
    return self;
    

}


-(void)creatSubView
{
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
//    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    flowLayout.minimumLineSpacing = 2;
    flowLayout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
    flowLayout.itemSize = CGSizeMake(TZWIDTH - 10,70);
    self.myCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0,0,TZWIDTH,170) collectionViewLayout:flowLayout];
    self.myCollectionView.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.myCollectionView];
    self.myCollectionView.showsHorizontalScrollIndicator = NO;
    
    self.myCollectionView.delegate = self;
    self.myCollectionView.dataSource = self;
    [self.myCollectionView registerClass:[TZjingPInDetailViewCell class] forCellWithReuseIdentifier:@"TZjingPInDetailViewCell"];
    
    //注册cell
   


}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section

{

    return self.allmodelarray.count;

}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    TZJingPinModel *model = [self.allmodelarray objectAtIndex:indexPath.row];
    
    static NSString *cellID = @"TZjingPInDetailViewCell";
    TZjingPInDetailViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
    cell.jingPinModel  = model;
//    cell.backgroundColor = [UIColor redColor];
    return cell;


}


//点击方法
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    TZJingPinModel *jingPin = self.allmodelarray[indexPath.row];
    NSString *Str= jingPin.specialId;
    [self.jingpinDeleget pushToJingPinDetail:Str];
    

}




-(void)setMyDic:(NSMutableDictionary *)myDic
{
    [self.allmodelarray removeAllObjects];
    NSMutableArray *array = myDic[@"list"];
    for (NSMutableDictionary *dic in array) {
        TZJingPinModel *jingPin = [[TZJingPinModel alloc]init];
        [jingPin setValuesForKeysWithDictionary:dic];
        [self.allmodelarray addObject:jingPin];
    }
    [self.myCollectionView reloadData];
    
    

}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
